﻿using Rimifier.Properties;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Rimifier.Support
{
  public class BackstoryList : IEnumerable<BackstoryListItem>, IThingList
  {
    public List<BackstoryListItem> List { get; private set; }

    public BackstoryList()
    {
      List = new List<BackstoryListItem>();

      List.AddRange(new[] {new BackstoryListItem
                           {
                             StoryId = 0,
                             StoryTitle = "Colony settler",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_ColonySettler
                           },
                           new BackstoryListItem
                           {
                             StoryId = 1,
                             StoryTitle = "Medieval farm oaf",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_MedievalFarmOaf
                           },
                           new BackstoryListItem
                           {
                             StoryId = 2,
                             StoryTitle = "Medieval lord",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_MedievalLord
                           },
                           new BackstoryListItem
                           {
                             StoryId = 3,
                             StoryTitle = "Urbworld entrepreneur",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_UrbworldEntrepreneur
                           },
                           new BackstoryListItem
                           {
                             StoryId = 4,
                             StoryTitle = "Deep space miner",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_DeepSpaceMiner
                           },
                           new BackstoryListItem
                           {
                             StoryId = 5,
                             StoryTitle = "Navy scientist",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_NavyScientist
                           },
                           new BackstoryListItem
                           {
                             StoryId = 6,
                             StoryTitle = "Military commissar",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_MilitaryCommissar
                           },
                           new BackstoryListItem
                           {
                             StoryId = 7,
                             StoryTitle = "Con Artist",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_ConArtist
                           },
                           new BackstoryListItem
                           {
                             StoryId = 8,
                             StoryTitle = "Space pirate",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_SpacePirate
                           },
                           new BackstoryListItem
                           {
                             StoryId = 9,
                             StoryTitle = "Pit Brawler",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_PitBrawler
                           },
                           new BackstoryListItem
                           {
                             StoryId = 10,
                             StoryTitle = "Illegal shipwright",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_IllegalShipwright
                           },
                           new BackstoryListItem
                           {
                             StoryId = 11,
                             StoryTitle = "Courtesean",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_Courtesean
                           },
                           new BackstoryListItem
                           {
                             StoryId = 12,
                             StoryTitle = "Space Marine",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_SpaceMarine
                           },
                           new BackstoryListItem
                           {
                             StoryId = 13,
                             StoryTitle = "Assassin",
                             StoryType = "Adulthood",
                             StoryDescription = Resources.Story_Assassin
                           },
                           new BackstoryListItem
                           {
                             StoryId = 14,
                             StoryTitle = "Midworld nerd",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_MidworldNerd
                           },
                           new BackstoryListItem
                           {
                             StoryId = 15,
                             StoryTitle = "Medieval slave",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_MedievalSlave
                           },
                           new BackstoryListItem
                           {
                             StoryId = 16,
                             StoryTitle = "Medieval lordling",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_MedievalLordling
                           },
                           new BackstoryListItem
                           {
                             StoryId = 17,
                             StoryTitle = "Urbworld urchin",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_UrbworldUrchin
                           },
                           new BackstoryListItem
                           {
                             StoryId = 18,
                             StoryTitle = "Vatgrown soldier",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_VatgrownSoldier
                           },
                           new BackstoryListItem
                           {
                             StoryId = 19,
                             StoryTitle = "Manufactured in a factory",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_ManufacturedInFactory
                           },
                           new BackstoryListItem
                           {
                             StoryId = 20,
                             StoryTitle = "Traded around",
                             StoryType = "Childhood",
                             StoryDescription = Resources.Story_TradedAround
                           }
      });
    }

    public BackstoryList(BackstoryTypes type): this()
    {
      switch (type)
      {
        case BackstoryTypes.Childhood:
          List = List.FindAll(where => where.StoryType == "Childhood");
          break;

        case BackstoryTypes.Adulthood:
          List = List.FindAll(where => where.StoryType == "Adulthood");
          break;
      }
    }

    public void Add(BackstoryListItem item)
    {
      List.Add(item);
    }

    public IEnumerator<BackstoryListItem> GetEnumerator()
    {
      return List.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
      return GetEnumerator();
    }

    public IThing GetThingById(String id)
    {
      return List.Find(item => item.StoryId == Int32.Parse(id));
    }

    public IThing GetThingByValue(String value)
    {
      return List.Find(item => item.StoryTitle == value);
    }

    public IThing GetThingByIndex(Int32 index)
    {
      return List[index];
    }

  }
}